package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.server.basic.EmpBean;
import com.xxxx.server.mapper.SalaryMapper;
import com.xxxx.server.pojo.Employee;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.ISalaryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@Service
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements ISalaryService {


    @Resource
    private SalaryMapper salaryMapper;



    /**
     * 查询所有的工资账套，并显示在主页面
     * @return
     */
    @Override
    public List<Salary> selectAllSob() {

        return salaryMapper.selectAllSob();
    }

    /**
     * 传入一个salary对象，并据此实现添加功能
     * 需要判断该对象
     * @param salary
     * @return
     */
    @Override
    public RespBean addSob(Salary salary) {
        if(1==salaryMapper.addSob(salary)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    /**
     * 根据传入的salary对象修改工资账套信息
     * @param salary
     * @return
     */
    @Override
    public RespBean updateSob(Salary salary) {
        if(1==salaryMapper.updateSob( salary)){
            return RespBean.success("修改成功");
        }
       return RespBean.error("修改失败");
    }

    /**
     * 根据传入的UserID删除对应的工资账套
     * @param userId
     * @return
     */
    @Override
    public RespBean deleteSob(Integer userId) {
        if(1==salaryMapper.deleteSob(userId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }


    /**
     * 查询出所有的工资账套
     * @return
     */
    @Override
    public List<Salary> selectAllSalarys() {

        return salaryMapper.selectAllSob();
    }


    /**
     * 实现分页
     * 查询用户信息，带部门信息和工资信息，
     * @param currentPage
     * @param size
     * @return
     */
    @Override
    public EmpBean pageHandler(Integer currentPage, Integer size) {

        EmpBean empBean = new EmpBean();
        //开启分页
        PageHelper.startPage(currentPage,size);

        //获取员工信息
        List<Employee> data = salaryMapper.pageHandler(currentPage,size);
        Long total = salaryMapper.getTotal();
        empBean.setTotal(total);

        empBean.setData(data);


        return empBean;
    }

    /**
     * 根据传入的eid修改对应的sid并返回修改成功信息
     * @param eid
     * @param sid
     * @return
     */
    @Override
    public RespBean updateSobCfg(Integer eid, Integer sid) {

        if(1==salaryMapper.updateSobCfg(eid,sid)){
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败!");
    }


}
